<title>ReaLua Misc and Util</title>

<p style="text-align: center; font-size: small">
<a href="index.html">Return to Index</a></p>

<h1 style="text-align: center;">ReaLua Miscellany and Utilities</h1>


<h2>Miscellany</h2>

<p>ReaLua puts the following few functions in the
global space, on the rationalization that the new
<code>print(<i>...</i>)</code> function is there,
so the other functions that deal with the
<a href="window.html">ReaLua Window</a>
go into the global space.
</p>

<dl>
	<dt><code><b>
print
	</b></code></dt>
	<dd>takes
		<code><i>...</i></code>
	</dd>
	<dd>returns
		<code>void <i></i></code>
	</dd>
</dl>

<p><code>print(<i>...</i>)</code> now sends its
output to the <a href="window.html">ReaLua Window</a>.
The old <code>stdio</code>-based
<code>print(<i>...</i>)</code> is stashed in the
<code>oldprint(<i>...</i>)</code> variable.
</p>

<dl>
	<dt><code><b>
oldprint
	</b></code></dt>
	<dd>takes
		<code><i>...</i></code>
	</dd>
	<dd>returns
		<code>void <i></i></code>
	</dd>
</dl>

<p><code>oldprint(<i>...</i>)</code> is the old
<code>stdio</code>-based <code>print(<i>...</i>)</code>
function that will hang if you print too much!
</p>

<dl>
	<dt><code><b>
input
	</b></code></dt>
	<dl>
		<dt>takes</dt>
		<dd><code>string <i>prompt</i></code></dd>
		<dd>optional <code>string <i>default</i></code></dd>
	</dl>
	<dd>returns
		<code>string <i>response</i></code>
	</dd>
</dl>

<p>
<code>input(string <i>prompt</i>, optional string <i>default</i>)</code>
displays a dialog box with the given <code><i>prompt</i></code>
string, and optionally a <code><i>default</i></code> response
string.  It returns the user's response as a string.
</p>


<dl>
	<dt><code><b>
exit
	</b></code></dt>
	<dd>takes
		<code>void<i></i></code>
	</dd>
	<dd>returns
		<code>void<i></i></code>
	</dd>
</dl>

<p><code>exit()</code> closes the
<a href="window.html">ReaLua Window</a>.  Use this
as the last line of a script to return the user to
Reaper.  Use as the first line of a script,
along with <code>reaper.Redraw()</code>,
to possess the Reaper muwhwaahahahaha!</p>

<blockquote><pre>
<code>exit()</code>
<code>reaper.Redraw()</code>
<code>reaper.CSurf_OnPlay()</code>
<code>reaper.sleep(3500)</code>
<code>reaper.CSurf_OnPlay()</code>
<code>reaper.sleep(3500)</code>
<code>reaper.CSurf_OnPlay()</code>
<code>reaper.sleep(3500)</code>
</pre></blockquote>

<dl>
	<dt><code><b>
cls
	</b></code></dt>
	<dd>takes
		<code>void<i></i></code>
	</dd>
	<dd>returns
		<code>void<i></i></code>
	</dd>
</dl>

<p><code>cls()</code> clears the output area of the
<a href="window.html">ReaLua Window</a>.

<dl>
	<dt><code><b>
dump
	</b></code></dt>
	<dl>
		<dt>takes</dt>
		<dd>optional <code>string <i>fileName</i></code></dd>
		<dd>optional <code>boolean <i>append</i></code></dd>
	</dl>
	<dd>returns
		<code>int <i>bytesWritten</i></code>
	</dd>
</dl>

<p>
<code>dump(</code>optional
<code>string <i>fileName</i>,</code>
optional <code>boolean <i>append</i>)</code> dumps
the contents of the <a href="window.html">ReaLua Window</a>'s
Output Area to a file.
</p>
<p>
Call <code>dump()</code> with no arguments to dump
to a file named "dump.txt" in the current
directory.  Call <code>dump()</code> with one
argument to control the file name (and directory).
If <code><i>append</i></code> is <code>true</code>,
the contents are appended to the named file.
</p>

<h2>Utilities</h2>

<p>The following few utility functions are in the
<a href="reaper.functions.html"><code>reaper</code></a> main table:
</p>

<dl>
	<dt><code><b>keystack</b></code></dt>
	<dd>takes <code>... <i>keys</i></code></dd>
	<dd>returns <code>int <i>evtCount</i></code></dd>
</dl>

<p><code>keystack(<i>...</i>)</code> sends the
<code>VK_BLAH</code>s to the Reaper window, as
matched key-down and key-up events.  It returns
the number of events inserted into the event queue.
It can be used as an alternative to the
<code>reaper.Main_OnCommand(int <i>code</i>, int <i>arg</i>)</code>
function, for things that have key commands.
</p>

<dl>
	<dt><code><b>sleep</b></code></dt>
	<dd>takes optional <code>int <i>milliseconds</i>=0</code></dd>
	<dd>returns <code>void<i></i></code></dd>
</dl>

<p><code>sleep()</code> simply calls the Win32
<code>Sleep(DWORD <i>ms</i>)</code> function.  Useful
to give things time to happen.
</p>

<dl>
	<dt><code><b>
Redraw
	</b></code></dt>
	<dd>takes
		<code>void<i></i></code>
	</dd>
	<dd>returns
		<code>void<i></i></code>
	</dd>
</dl>

<p><code>Redraw()</code> simply calls the Win32
<code>Redraw(<i></i>)</code> function with the
Reaper window as its target.  Useful to show what's
going on.
</p>

<dl>
<dt>
<code><b>getmetatable(string <i>name</i>)</b></code>
</dt>
<dd>
gets the Reaper Type metatable by name,
the one which holds its <code>_tostring</code>
(and maybe more):
</dd>
</dl>

<code>
> mt = <b>reaper.getmetatable( "reaper.MediaItem" )</b><br>
> for k,v in pairs(mt) do<br>
>>   print( k, v )<br>
>> end<br>
__tostring      function: 020A6560<br>
>
</code>

<p></p>
<p></p>
<p></p>
<p></p>

<p style="text-align: center; font-size: small">
<a href="index.html">Return to Index</a></p>
